(defun ruby-eval-buffer ()
  (interactive)
  "Evaluate the buffe with ruby."
  (shell-command-on-region (point-min) (point-max) "ruby"))

;; method which puts "#!/usr/bin\n\n" in current buffer
;; and bound to "Esc #" keys
(fset 'ruby-hash-header
      "#!/usr/bin/ruby\C-m\C-m")
(global-set-key "\C-[#" 'ruby-hash-header) ;; ESC # = #!/usr/bin/ruby

(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
                                     interpreter-mode-alist))
(autoload 'run-ruby "inf-ruby"
  "Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby"
  "Set local key defs for inf-ruby in ruby-mode")
(autoload 'rubydb "rubydb3x" "Debug ruby db")
;;(add-hook 'ruby-mode-hook
;;        '(lambda () (inf-ruby-keys)))



(defun ruby-custom-setup()
  (add-to-list 'hs-special-modes-alist
               (list 'ruby-mode
                     (concat ruby-block-beg-re "\|{")
                     (concat ruby-block-end-re "\|}")
                     "#"
                     'ruby-forward-sexp nil))
  (define-prefix-command 'hs-map nil "Hide/Show-")
  (define-key hs-map "H" 'hs-hide-all)
  (define-key hs-map "S" 'hs-show-all)
  (define-key hs-map "h" 'hs-hide-block)
  (define-key hs-map "s" 'hs-show-block)
  (define-key hs-map "l" 'hs-hide-level)
  (define-key hs-map "t" 'hs-toggle-hiding)
  (global-set-key "\M-o" hs-map)
  
  (define-key ruby-mode-map "\M-\C-i" 'rct-complete-symbol)
  
  (hs-minor-mode t)
  (reveal-mode t))

(add-hook 'ruby-mode-hook
          (lambda()
            (inf-ruby-keys)
            (require 'ruby-electric)
            (require 'rinari)
            (local-set-key [f1] 'ri)
            (ruby-electric-mode t)
            (ruby-custom-setup)
            (imenu-add-to-menubar "IMENU")))
